package com.serviceprovider.business.module.report.model;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.admin.user.model.Saveable;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class CustomReport extends Saveable {
    private static final String CONCAT           = "#";
    private static final long   serialVersionUID = 1L;
    private List<Integer>       payeesId         = new ArrayList<Integer>();
    private List<String>        selectedFees     = new ArrayList<String>();
    private Date                dateFrom;
    private Date                dateTo;
    private String              name;
    private String              reportType;
    private String              transactionStatus;
    private int                 userId;

    public void setUserId(int id) {
        userId = id;
    }

    public int getUserId() {
        return userId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setTransactionStatus(String status) {
        transactionStatus = status;
    }

    public String getTransactionStatus() {
        return transactionStatus;
    }

    public Date getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    public Date getDateTo() {
        return dateTo;
    }

    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    public void setReportType(String type) {
        reportType = type;
    }

    public String getReportType() {
        return reportType;
    }

    public void setPayeesId(Object objId) {
        if (objId instanceof Object[]) {
            payeesId = new ArrayList<Integer>();

            for (Object id : ((Object[]) objId)) {
                payeesId.add(Integer.parseInt(String.valueOf(id)));
            }
        } else if (objId instanceof Integer) {
            payeesId = Arrays.asList((Integer) objId);
        } else if (objId instanceof String) {
            payeesId = Arrays.asList(Integer.parseInt((String) objId));
        }
    }

    public void setPayeesId(List<Integer> payeesId) {
        this.payeesId = payeesId;
    }

    public List<Integer> getPayeesId() {
        return payeesId;
    }

    public List<String> getSelectedFees() {
        return selectedFees;
    }

    public void setSelectedFees(List<String> selectedFee) {
        this.selectedFees = selectedFee;
    }

    public String getPayeeIdString() {
        if (getPayeesId() == null) {
            return "";
        }

        StringBuffer payeeIds = new StringBuffer();
        String       concat   = "";

        for (Integer payeeId : getPayeesId()) {
            payeeIds.append(concat).append(payeeId);
            concat = CONCAT;
        }

        return payeeIds.toString();
    }

    public String getSelectedFeesString() {
        if (getSelectedFees() == null) {
            return "";
        }

        StringBuffer payeeIds = new StringBuffer();
        String       concat   = "";

        for (String selectedFee : getSelectedFees()) {
            payeeIds.append(concat).append(selectedFee);
            concat = CONCAT;
        }

        return payeeIds.toString();
    }

    public void setPayeesIdString(String string) {
        if (string != null) {
            payeesId = new ArrayList<Integer>();

            String[] idStrings = string.split(CONCAT);

            for (String id : idStrings) {
                try {
                    payeesId.add(Integer.valueOf(id));
                } catch (Exception e) {}
            }
        }
    }

    public void setSelectedFees(String string) {
        if (string != null) {
            selectedFees = new ArrayList<String>();

            String[] idStrings = string.split(CONCAT);

            for (String fee : idStrings) {
                selectedFees.add(fee);
            }
        }
    }

    @Override
    public boolean equals(Object obj) {
        if ((obj == null) ||!(obj instanceof CustomReport)) {
            return false;
        }

        CustomReport b  = (CustomReport) obj;
        boolean      eq = ((id == null) && (b.id == null)) || ((id != null) && id.equals(b.id));

        if (!eq) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return (id != null)
               ? id.hashCode()
               : 0;
    }
}



